package me.lijf.mqlite.redis.stream;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.stream.StreamListener;
import org.springframework.stereotype.Component;

import java.util.Map;

@Log4j2
@Component
public class StreamQueListener2 implements StreamListener<String, MapRecord<String,String,String>> {
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private RedisStreamUtil redisStreamUtil;
    @Autowired
    private StreamQueConfig config;

    @SneakyThrows
    @Override
    public void onMessage(MapRecord<String, String, String> entries) {
        String key=entries.getStream();
        String id=entries.getId().getValue();
        Map<String,String> message=entries.getValue();
        if(message==null) return;
        String str=objectMapper.writeValueAsString(message);
        log.info("lijf3_2_1收到stream={},id={}的消息{}，但不ack",key,id,str);
//        redisStreamUtil.ack(key,"lijf3_2",id);
    }
}
